/*
 ------------------------------------------------------------------------------
 Copyright (C) 2013 Eternal Games.

 This file is part of the GLQuake source code.

 The GLQuake source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The GLQuake source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the GLQuake source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// cm_local.h - local header to all renderer files
//


#ifndef __CM_LOCAL_H__
#define __CM_LOCAL_H__


#include "../common/common.h"
#include "cm_public.h"


/*
 ==============================================================================

 MODEL MANAGER

 ==============================================================================
*/

#define MAX_CLIP_MODELS					2048

enum clipModelType_t {
	CLIP_MODEL_INLINE
};

struct clipLeaf_t {
	// Common with node
	glqBounds				bounds;

	// Leaf specific
	byte *					compressedPVS;
};

struct clipNode_t {
	// Common with leaf

	// Node specific
	int todo;
};

struct clipClipNode_t {

};

struct clipInlineModel_t {
	glqBounds				bounds;
};

struct clipMap_t {
	bool					loaded;

	char					name[MAX_PATH_LENGTH];
	int						size;

	int						checkCount;			// For multi-check avoidance

	// BSP data structures
	int						numEntityChars;
	char *					entityString;

	int						numPlanes;
	glqPlane *				planes;

	byte *					pvs;
	byte *					noPVS;

	int						numLeafs;
	clipLeaf_t *			leafs;

	int						numNodes;
	clipNode_t *			nodes;

	int						numClipNodes;
	clipClipNode_t *		clipNodes;

	int						numInlineModels;
	clipInlineModel_t *		inlineModels;
};

struct clipModel_t {
	char					name[MAX_PATH_LENGTH];
	bool					defaulted;

	clipModelType_t			type;
	void *					data;
	int						size;

	clipModel_t *			nextHash;
};

clipModel_t *		CM_FindModel (const char *name);

void				CM_LoadInlineModel (int index, void *data);

void				CM_CreateBoxModel ();

void				CM_ClearModels ();

void				CM_InitModels ();
void				CM_ShutdownModels ();

/*
 ==============================================================================

 GLOBALS

 ==============================================================================
*/

struct clipStats_t {
	int						traces;
	int						leafTraces;

	int						tests;

	int						leafPoints;
};

extern clipMap_t			cm;

extern clipStats_t			cm_stats;

extern cvar_t *				cm_showStats;
extern cvar_t *				cm_skipModels;
extern cvar_t *				cm_skipPVS;


#endif	// __CM_LOCAL_H__